<%layout("/common/_layout.html"){ %>
  <%#ajax userTable:{%>
  <div class="am-cf am-padding">
    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">系统管理</strong> / <small>账号管理</small></div>
  </div>
   <div class="am-g">
     <form class="am-form" id="list-form" action="${base}/account/list" method="post">
     <input type="hidden" id="keywords" name="keywords" value='${keywords!""}' />
     <table class="am-table am-table-bordered am-table-radius table-main" style="padding:0;">
                 <tbody>
                 <tr>
                     <th class="am-text-middle">用户名</th>
                     <td>
                         <div class="am-u-sm-10">
                            <input type="text" class="am-form-field" id="name" value="${name!}" placeholder="请输入用户名">
                         </div>
                     </td>
                    <th class="am-text-middle">所属机构</th>
                     <td>
                         <div class="am-u-sm-10">
                             <select data-am-selected="{btnSize:'sm',maxHeight: 400}" name="org_id" id="org_id">
                                 <%for(orgNode in orgList){%>
                                 <option value="${orgNode.value}" <%if(org_id==orgNode.value){%>
                                 selected
                                 <%}%>>${orgNode.key}</option>
                                 <%}%></select>
                         </div>
                     </td>
                 </tr>
                 <tr>
                     <th class="am-text-middle">角色名</th>
                     <td>
                         <div class="am-u-sm-10">
                            <input type="text" class="am-form-field" id="roleName" value="${roleName!}" placeholder="请输入角色名">
                         </div>
                     </td>
                     <th class="am-text-middle"></th>
                                     <td>
                                         <div class="am-u-sm-10">
                                         </div>
                                     </td>
                 </tr>
                  <tr>
                     <td colspan="4">
                         <div align='right'>
                              <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary"
                                    id="submit-btn">搜索
                              </button>
                             </div>
                         </td>
                     </tr>
                 </tbody>
             </table>
             <div class="am-u-sm-12 am-u-md-12" style="padding:0 1.6rem 1.6rem 1rem;margin:0;">
                     <div class="am-btn-toolbar" style="padding-left:.5rem;">
                         <div class="am-btn-group am-btn-group-xs">
                             <%if(so.hasPermission("ACCOUNT_ADD")) {%>
                                 <button type="button" class="am-btn am-btn-default" onclick="location.href='${base}/account/add'"><span class="am-icon-plus"></span>新增</button>
                             <%}%>
                             <%if(so.hasPermission("ACCOUNT_DELETE")) {%>
                                 <button type="button" id="deleteButton" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteAll('${base}/account/delete')"><span class="am-icon-trash-o"></span> 删除</button>
                             <%}%>
                         </div>
                     </div>
                 </div>
   </form>
   <div class="am-g">
     <div class="am-u-sm-12">
      <div class="am-scrollable-horizontal">
         <table class="am-table am-table-striped am-table-hover table-main">
             <thead>
                 <tr class="am-text-nowrap">
                     <th class="table-check"><input type="checkbox"  id="allCheck"/></th>
                     <th>用户名</th>
                     <th>姓名</th>
                     <th>电话</th>
                     <th>添加时间</th>
                     <th>角色</th>
                     <th>所属机构</th>
                     <th>状态</th>
                     <th>操作</th>
                 </tr>
             </thead>
          <tbody>
             <%for(list in pager.list!){%>
                <tr>
                 <td><input type="checkbox" name="ids" value="${list.id}"></td>
                 <td>${list.user_name}</td>
                 <td>${list.real_name}</td>
                 <td>${list.telephone}</td>
                 <td>${list.created_time, dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
                 <td>${list.roleName}</td>
                 <td>${list.orgName}</td>
                 <td>${list.isAccountEnabled!?"可用":"禁用"}</td>
                 <td>
                 <div class="am-btn-toolbar">
                     <div class="am-btn-group am-btn-group-xs"> 
                        <%if(so.hasPermission("ACCOUNT_EDIT")) {%>      
                            <button onclick="location.href='${base}/account/edit?id=${list.id}'" type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" ><span class="am-icon-pencil-square-o"></span>编辑</button>
                        <%}%>
                        <button onclick="onResetPassword('${list.id}','${list.user_name}','${list.real_name}')" type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" ><span class="am-icon-pencil-square-o"></span>重置密码</button>
                     </div>
                   </div>
                 </td>
               </tr>
             <%}%> 
          </tbody>
       </table>
       </div>
        <div class="am-cf">
           <!-- 分页 -->
           <%if (pager.list.~size > 0){%>
               <div class="am-fr">
                   <% include("/admin/common_pager.tpl"){}%>
               </div>
           <%}else{%>
               <div class="am-kai">
                 <h3>没有找到任何记录!</h3>
               </div>
           <%}%>
        </div>
       <%}%>
     </div>
   </div>
   <script type="text/javascript">
   $(function(){
      var keywordsObj = {};
      $("#submit-btn").on("click",function(){
        if($("#name").val()){
          keywordsObj.name = $("#name").val();
        }
        if($("#org_id").val()){
           keywordsObj.org_id = $("#org_id").val();
        }
        if($("#roleName").val()){
           keywordsObj.roleName = $("#roleName ").val();
         }
        var keywords = "";
        if(!$.isEmptyObject(keywordsObj)){
          keywords = JSON.stringify(keywordsObj);
        }
        console.log("keywords = "+ keywords);

        $("#keywords").val(keywords);
        $("#list-form").submit();
      });      
   });
   function onResetPassword(id,name,real){
      parent.layer.alert("用户(" + name + "," + real +")"+ "的密码将被重置为 pt5b@#B5TP", function(index){
          $.ajax({ 
            url: "${base}/account/resetPassword?id=" + id, 
            success: function(){
                parent.layer.msg('重置成功');
          }});
          parent.layer.close(index);
      });
   };
   </script>
<%}%>
